package com.hnly.djdl.components

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.PaintingStyle
import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.hnly.djdl.theme.MainThemeColor

@Composable
fun BorderLineBox(
    modifier: Modifier,
    left: Boolean = true,
    top: Boolean = true,
    right: Boolean = true,
    bottom: Boolean = true,
    stokeWidth: Dp = 2.dp,
    strokeColor: Color = MainThemeColor,
    content: @Composable BoxScope.() -> Unit,
) {
    Box(
        modifier = modifier.drawBehind {
            drawIntoCanvas { canvas ->
                val paint = Paint().apply {
                    color = strokeColor
                    this.strokeWidth = stokeWidth.toPx()
                    style = PaintingStyle.Stroke
                    pathEffect = PathEffect.dashPathEffect(floatArrayOf(50f, 10f), 0f)
                }
                if (left) {
                    // Draw left border
                    canvas.drawLine(Offset(0f, 0f), Offset(0f, size.height), paint)
                }
                if (bottom) {
                    // Draw bottom border
                    canvas.drawLine(
                        Offset(0f, size.height),
                        Offset(size.width, size.height),
                        paint
                    )
                }
                if (top) {
                    // Draw top border
                    canvas.drawLine(Offset(0f, 0f), Offset(size.width, 0f), paint)
                }
                if (right) {
                    // Draw right border
                    canvas.drawLine(
                        Offset(size.width, 0f),
                        Offset(size.width, size.height),
                        paint
                    )
                }
            }
        },
        content = content
    )
}